package com.ruoyi.live.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.live.utils.TxLiveUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.live.mapper.TbRoomMapper;
import com.ruoyi.live.domain.TbRoom;
import com.ruoyi.live.service.ITbRoomService;

/**
 * 直播房间Service业务层处理
 * 
 * @author sun
 * @date 2023-01-30
 */
@Service
public class TbRoomServiceImpl implements ITbRoomService 
{
    @Autowired
    private TbRoomMapper tbRoomMapper;

    /**
     * 查询直播房间
     * 
     * @param roomId 直播房间主键
     * @return 直播房间
     */
    @Override
    public TbRoom selectTbRoomByRoomId(Integer roomId)
    {
        return tbRoomMapper.selectTbRoomByRoomId(roomId);
    }

    /**
     * 查询直播房间列表
     * 
     * @param tbRoom 直播房间
     * @return 直播房间
     */
    @Override
    public List<TbRoom> selectTbRoomList(TbRoom tbRoom)
    {
        return tbRoomMapper.selectTbRoomList(tbRoom);
    }

    /**
     * 新增直播房间
     * 
     * @param tbRoom 直播房间
     * @return 结果
     */
    @Override
    public int insertTbRoom(TbRoom tbRoom)
    {
        tbRoom.setCreateTime(DateUtils.getNowDate());
        //--2 生成推流地址
        tbRoom.setRoomNo(""+ IdWorker.getId());
        String pushUrl = TxLiveUtils.makePushUrl(tbRoom.getRoomNo(), tbRoom.getCloseTime());
        tbRoom.setPushUrl(pushUrl);

        //--3 生成播放地址
        String playUrl = TxLiveUtils.makePlayUrl(tbRoom.getRoomNo());
        tbRoom.setPlayUrl(playUrl);
        return tbRoomMapper.insertTbRoom(tbRoom);
    }

    /**
     * 修改直播房间
     * 
     * @param tbRoom 直播房间
     * @return 结果
     */
    @Override
    public int updateTbRoom(TbRoom tbRoom)
    {
        tbRoom.setUpdateTime(DateUtils.getNowDate());
        return tbRoomMapper.updateTbRoom(tbRoom);
    }

    /**
     * 批量删除直播房间
     * 
     * @param roomIds 需要删除的直播房间主键
     * @return 结果
     */
    @Override
    public int deleteTbRoomByRoomIds(Integer[] roomIds)
    {
        return tbRoomMapper.deleteTbRoomByRoomIds(roomIds);
    }

    /**
     * 删除直播房间信息
     * 
     * @param roomId 直播房间主键
     * @return 结果
     */
    @Override
    public int deleteTbRoomByRoomId(Integer roomId)
    {
        return tbRoomMapper.deleteTbRoomByRoomId(roomId);
    }
}
